#pragma once
struct Work;
struct Session
{
	int m_nIdx;
	evutil_socket_t m_fd;
	struct bufferevent* m_bev;
	CNetPacket m_netPacket;
	Session* m_next;
	Work *m_pOwnWork;
	Session() :m_netPacket(0)
	{
		m_pOwnWork = NULL;
		m_nIdx = 0;
		m_fd = 0;
		m_bev = NULL;
		m_next = NULL;
		m_netPacket.clear();
	}
};

struct SessionList
{
	Session* m_SessionList;
	Session* m_head;
	Session* m_end;
	int m_nSessionNum;

	SessionList()
	{
		m_nSessionNum = 0;
		m_SessionList = NULL;
		m_head = NULL;
		m_end = NULL;
	}

};

struct Work
{
	HANDLE   m_Handle;
	struct event_base* m_EvBase;
	bool     m_boThreadExit;
	int		 m_nSessionNum;
	SessionList* m_SessionList;
	CRITICAL_SECTION m_Lock;
	Work()
	{
		m_EvBase = NULL;
		m_nSessionNum = 0;
		m_SessionList = NULL;
		m_Handle = NULL;
		m_boThreadExit = false;
	}

	Session* getFreeSession();
	void pushFreeSession(Session* pSession);

};
struct Server
{
	Work *m_work;
	HANDLE m_Handle;
	struct event_base* m_EvBase;
	struct evconnlistener* m_EvconnListener;
	bool n_boThreadExit;
	int	m_nWorkNum;
	int m_nPort;
	int m_nSessionNum;
	int read_timeout;
	int write_timeout;
	int m_nCurWorkNum;
	bool m_boStart;
	Server()
	{
		m_Handle = NULL;
		m_work = NULL;
		m_EvBase = NULL;
		m_nWorkNum = 0;
		m_nPort = 0;
		m_nSessionNum = 0;
		m_EvconnListener = NULL;
		m_boStart = false;
		m_nCurWorkNum = 0;
		read_timeout = 0;
		write_timeout = 0;
		n_boThreadExit = false;
	}
};